﻿<Window x:Class="ResourceBlender.Express.WinFindResource"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:ResourceBlender.Express"
    xmlns:converters="clr-namespace:ResourceBlender.Express.Converters"
    xmlns:validators="clr-namespace:ResourceBlender.Express.Validators"
    xmlns:props="clr-namespace:ResourceBlender.Express.Properties"
    loc:WindowService.EscapeClosesWindow="True"
    x:Name="root"
    Title="Find Resource" MinHeight="350" Height="600" MinWidth="400" Width="500"
    WindowStartupLocation="CenterOwner"
    Style="{StaticResource {x:Type Window}}" Icon="/ResourceBlenderExpress;component/Resources/images/resourceblender.ico">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Close" Executed="CloseWindow" />
        <CommandBinding Command="ApplicationCommands.Find" Executed="FindResources" CanExecute="CanExecuteFindResources" />
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" />
        <CommandBinding Command="ApplicationCommands.Save" Executed="SelectResource" CanExecute="CanExecuteSelectResource" />
    </Window.CommandBindings>
    <Window.Resources>
        <converters:WidthConverter x:Key="WidthConverter" />
        <converters:LanguageCodeConverter x:Key="LanguageCodeConverter" />
        <props:Settings x:Key="settings"/>
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <StatusBar DockPanel.Dock="Bottom">
            <StatusBarItem x:Name="lblStatus" Visibility="Hidden">Searching...</StatusBarItem>
            <ProgressBar x:Name="prgStatus" IsIndeterminate="True" Visibility="Hidden" IsTabStop="False" />
        </StatusBar>
        <Grid DockPanel.Dock="Top" Margin="6">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            
            <Label Grid.Row="0" Grid.Column="0">Language</Label>
            <ComboBox x:Name="cboLanguages" Grid.Row="0" Grid.Column="1" ItemTemplate="{StaticResource LanguageListItem}" SelectedValuePath="Key" SelectionChanged="cboLanguages_SelectionChanged" />
            
            <Label Grid.Row="1" Grid.Column="0">Criteria</Label>
            <ComboBox x:Name="cboCriteria" Grid.Row="1" Grid.Column="1" SelectionChanged="UpdateFilters">
                <ComboBoxItem Tag="contains" IsSelected="true">Contains</ComboBoxItem>
                <ComboBoxItem Tag="startswith">Starts With</ComboBoxItem>
                <ComboBoxItem Tag="endswith">Ends With</ComboBoxItem>
            </ComboBox>
            
            <Label Grid.Row="2" Grid.Column="0">Translation</Label>
            <TextBox x:Name="txtTranslation" Grid.Row="2" Grid.Column="1" TextChanged="UpdateFilters">
                <Binding Path="Translation">
                    <Binding.ValidationRules>
                        <validators:StringValidationRule ErrorMessage="Search text must be specified" MinimumLength="0" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox>
            
            <CheckBox x:Name="chkOnlyExisting" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Center" Checked="UpdateFilters" Unchecked="UpdateFilters">Only resources already used in this application</CheckBox>
            
            <CheckBox x:Name="chkLiveFilter" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" DataContext="{StaticResource settings}" Content="Filter while typing" IsChecked="{Binding Default.LiveFilter,Mode=TwoWay}" />

            <Button Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Right" Margin="0,2,2,2" Content="Search" MinWidth="70" Command="ApplicationCommands.Find" IsDefault="True">
                <Button.Style>
                    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=chkLiveFilter, Path=IsChecked}" Value="True">
                                <Setter Property="Button.IsEnabled" Value="false"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>

            <ListView x:Name="lstResources" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2"
                      GridViewColumnHeader.Click="OnColumnHeaderClick" MouseDoubleClick="lst_MouseDoubleClick"
                      SelectionMode="Single" ItemsSource="{Binding}" SelectedValuePath="resourceid" SelectionChanged="lst_SelectionChanged">
                <ListView.View>
                    <GridView x:Name="grdResources">
                        <GridViewColumn Header="ID">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate DataType="resourceid">
                                    <TextBlock Style="{StaticResource FullWidthTextBlock}" Text="{Binding resourceid}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="Available Languages">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate DataType="numlanguages">
                                    <TextBlock Style="{StaticResource FullWidthTextBlock}" Text="{Binding numlanguages}" TextAlignment="Center" ToolTip="{Binding StringFormat=This resource has been translated into {0} languages,Path=numlanguages}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="{Binding ElementName=cboLanguages,Path=SelectedValue,Converter={StaticResource LanguageCodeConverter}}"
                                        Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListView}},Converter={StaticResource WidthConverter},ConverterParameter=200}">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate DataType="translation">
                                    <TextBlock Style="{StaticResource FullWidthTextBlock}" Text="{Binding translation}" ToolTip="{Binding comment}" TextAlignment="Left"  />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>

            <Grid Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                
                <loc:ImageButton Grid.Column="0" MinWidth="70" Command="ApplicationCommands.Help" Image="Resources/images/question_16.png" ImageLocation="Left" Text="Help" />
                <Button Grid.Column="2" x:Name="btnSelect" MinWidth="140" Command="ApplicationCommands.Save" CommandParameter="{Binding ElementName=lstResources,Path=SelectedItem}" Content="Select Resource"/>
                <Button Grid.Column="3" x:Name="btnCancel" MinWidth="70" Command="ApplicationCommands.Close">Cancel</Button>
            </Grid>
        </Grid>
    </DockPanel>
</Window>
